package com.sx.micowell.module.login

import android.text.TextUtils
import android.view.View
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.data.DataBindingConfig
import com.example.mvvm.until.LogUtils
import com.gyf.immersionbar.ImmersionBar
import com.sx.micowell.BR
import com.sx.micowell.R
import com.sx.micowell.databinding.ActRegisterBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyActivity
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.framework.model.RegisterToForgetPwdModel

/**
 * @Author: YY
 * @Time: 2021/8/13
 * @Describe 注册 或 忘记密码
 * type 0 注册 1 忘记密码 2 修改密码
 */
@Route(path = RoutePath.REGISTER_TO_FORGET_PWD)
class RegisterToForgetPwdActivity : MyActivity<ActRegisterBinding>() {

    @Autowired(name = IntentKey.TYPE)
    @JvmField
    var type: Int = 0

    @Autowired(name = IntentKey.DATA)
    @JvmField
    var phone: String = ""

    private var viewModel: RegisterToForgetPwdModel? = null

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.act_register, BR.viewModel, viewModel)
    }

    override fun initViewModel() {
        super.initViewModel()
        viewModel = getActivityScopeViewModel(RegisterToForgetPwdModel::class.java)
    }

    override fun initView() {
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(true).init()
        if (type == 1) {
            binding.tvTitle.text = "忘记密码"
            binding.tvContent.visibility = View.GONE
            binding.layout1.visibility = View.GONE
        } else if (type == 2) {
            binding.tvTitle.text = "修改登录密码"
            binding.tvContent.visibility = View.GONE
            binding.layout1.visibility = View.GONE

            if (!TextUtils.isEmpty(phone)) {
                binding.editPhone.setText(phone)
                binding.editPhone.isFocusable = false
            }
        }
    }

    override fun initData() {
        LogUtils.d("initData $type")
        viewModel?.type = type
        if (type == 0){
            viewModel?.userAgreement()
        }

        if (!TextUtils.isEmpty(phone)) {
            viewModel?.setPhoneNum(phone)
        }
    }
}